package jp.tuyano.sample.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import jp.tuyano.core.PMF;
import jp.tuyano.sample.client.form.ReferenceForm;
import jp.tuyano.sample.client.reference.ReferenceService;
import jp.tuyano.sample.server.entity.Employee;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class ReferenceServiceImpl extends RemoteServiceServlet implements
        ReferenceService {

    private static final long serialVersionUID = 1L;

    public List<ReferenceForm> getAllData() {
        
        PersistenceManager pm = PMF.get().getPersistenceManager();
        Query query = pm.newQuery(Employee.class);
        @SuppressWarnings("unchecked")
        List<Employee> result = (List<Employee>) query.execute();
        List<ReferenceForm> clientResult = new ArrayList<ReferenceForm>();
        for (Employee emp: result) {
            ReferenceForm rForm = new ReferenceForm(emp.getId(),
                    emp.getLastName(), emp.getFirName(),
                    emp.getSex(), emp.getEnterDate());
            clientResult.add(rForm);
        }
        return clientResult;
    }
}
